package com.hq.ims.data.service;

import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.dao.CompanyServiceTypeHistoryMapper;
import com.hq.ims.data.entity.CompanyServiceTypeHistory;
import com.hq.ims.data.entity.Dict;
import com.hq.ims.data.entityenum.EnumDataType;
import com.hq.ims.data.vo.CompanyServiceTypeMapstruct;
import com.hq.mybatis.base.BaseService;
import com.hq.utils.util.ObjectUtils;
import com.hq.web.utils.SpringBootValidateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author jiang bai ping
 * @Email 526666031@qq.com
 * @DateTime 2024-10-29 14:44:52
 * @Detail 企业产业标记服务实现类
 */
@Service
public class BaseCompanyServiceTypeHistoryService extends BaseService<CompanyServiceTypeHistoryMapper, CompanyServiceTypeHistory> {

    @Resource
    private BaseDictService baseDictService;

    public List<CompanyServiceTypeHistory> getCompanyAllServiceTypeList(String id, Integer dataType) {
        return this.lambdaQuery().eq(CompanyServiceTypeHistory::getCompanyCheckId, id).eq(CompanyServiceTypeHistory::getDataType, dataType).list();
    }


    public CompanyServiceTypeHistory addData(CompanyServiceTypeMapstruct.SaveVo vo) {
        //验证
        SpringBootValidateUtils.validate(vo, VdAdd.class);
        Dict companyServiceTypeDict = baseDictService.getById(vo.getServiceTypeId());
        ObjectUtils.isNullThrow(companyServiceTypeDict, "产业标记不存在");

//        boolean existsCompanyIdAndServiceTypeId = this.isExistsCompanyIdAndServiceTypeId(vo.getCompanyId(), vo.getServiceTypeId(), null);
//        BooleanUtils.isTrueThrow(existsCompanyIdAndServiceTypeId, "该产业标记已经存在");

        //账值新的对象
        CompanyServiceTypeHistory entity = new CompanyServiceTypeHistory();
        entity.setCompanyCheckId(vo.getCheckId());
        entity.setCompanyId(vo.getCompanyId());
        entity.setServiceTypeId(companyServiceTypeDict.getDictId());
        entity.setServiceTypeName(companyServiceTypeDict.getName());
        entity.setDataType(EnumDataType.After);
        entity.insert();
        return entity;
    }

    @Transactional(rollbackFor = Exception.class)
    public void delByCompanyId(String companyId) {
        this.lambdaUpdate().eq(CompanyServiceTypeHistory::getCompanyId,companyId).remove();
    }
}
